package com.example.mqttmodule.config;

import lombok.extern.log4j.Log4j2;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended;
import org.eclipse.paho.client.mqttv3.MqttMessage;

@Log4j2
public class MqttPushCallback  implements MqttCallbackExtended {

    @Override
    public void connectComplete(boolean reconnect, String serverURI) {
        log.info("MQTT连接成功: {}, 重连: {}", serverURI, reconnect);
    }

    @Override
    public void connectionLost(Throwable cause) {
        log.error("MQTT连接丢失", cause);
    }

    @Override
    public void messageArrived(String topic, MqttMessage message) {
        log.info("收到消息 - Topic: {}, Payload: {}", topic, new String(message.getPayload()));
        // 这里添加您的消息处理逻辑
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {
        log.debug("消息投递完成: {}", token.getMessageId());
    }
}